module Main where

import Control.Monad
import Language
import Definitions
import qualified SExpressions as SE
import Data.Maybe
import Data.List
import Evaluation
import qualified Environment as Env
import qualified ResultState as RS
import Accessor
import Result
import Preprocessor


exec input = case SE.parse input of
               (Just input) -> let prog = List (Symbol "seq" Nothing : (map translate input)) Nothing in
                               let tproc = bindPrelude >> evaluate prog in
                               let tree = executionTree (initialMachineState tproc) in
                               traces tree
               Nothing      -> error "Bad input"
             

run file = do input <- load file
              return $ exec input

w file = do output <- run file
            writeFile "output.txt" (unlines $ map show output)


tracs = run "test"


trails = do traces <- tracs
            return $ map getTrail traces
  where
    getTrail (_, Failure _)  = Failure ()
    getTrail (_, Success ms) = Success $ getter trail ms
